var submitted=false;
function displayConfirmation() {
	$("textarea, input").fadeOut(3000, function() {
		$("#confirm").fadeIn(3000);
		});
	}
function redirect()
	{parent.location='__UP_pageUrl__';}

$(document).ready(function(){
	$('#leftDiv').width($('.textarea').width()+2);
	$('#rightDiv').width($('.input').width()+2);
	$('textarea').width($('.textarea').width()-6);
	$('input[type=text]').width($('.input').width()-6);
	$('form, .xboxcontent').width($('.textarea').width()+$('.input').width()+58);
	$('.xsnazzy').width($('.textarea').width()+$('.input').width()+64);
	$("input[type=text], textarea").change(function () {                     
		$(this).val(
			$.trim($(this).val())
			);
		});
		
function moveCursorToEnd(el) {
    var idx = el.value.length;
    if (el.setSelectionRange) {
		setTimeout(function () {el.setSelectionRange(idx, idx);},0);
		}
    else if (el.createTextRange) {
		var range = el.createTextRange();
		range.collapse(true);
		range.moveEnd('character', idx);
		range.moveStart('character', idx);
		range.select();
		}
	}
	
$("#entry_0, #entry_1, textarea").focus(function(){
	if( this.value == this.defaultValue ) {
		$(this).val("").css("color","__UP_textInputFontColor__"); moveCursorToEnd(this);
		}
	}).blur(function() {
		if( !this.value.length ) {
			$(this).val(this.defaultValue).css("color","__UP_labelsFontColor__");
			}
		});

$("#entry_2").focus(function(){
	if( this.value == this.defaultValue ) {
		$(this).val("http://").css("color","__UP_textInputFontColor__"); moveCursorToEnd(this);
		}
	}).blur(function() {
		if( !this.value.length || $("#entry_2").val() == "http://" ) {
			$(this).val(this.defaultValue).css("color","__UP_labelsFontColor__");
			}
	});

$("input[type=text]").keypress(function(e) {
	if ( e.which == 13 ) e.preventDefault();
	});

jQuery.validator.addMethod("noComment", function(value, element) {
	return value != element.defaultValue;
	}, "Please enter your comment.");

jQuery.validator.addMethod("noName", function(value, element) {
	return value != element.defaultValue;
	}, "Please enter your name.");

	
jQuery.validator.addMethod("noEmail", function(value, element) {
	return value != element.defaultValue;
	}, "Please enter your Email.");

$("#entry_2").change(function() {
	if ($("#entry_2").val() == "URL" || $("#entry_2").val() == "http://" || $("#entry_2").val() == "") {
		$("#entry_2").attr("class","valid");
		}
	else {$("#entry_2").attr("class","url");}
	});

$("#enrollForm").validate({
	errorPlacement: function(error, element) {
		error.appendTo( element.parent("div").next("div") );
		},
	submitHandler: function() {
		if ($("#entry_2").val() == "URL") {$("#entry_2").val("");}
			$("#send").bind("click", function() { return false; });
		form.submit(); 
		} 
	});   

$("iframe").load(function() {
	if(submitted)
	__UP_onSubmit__
	});
});
